package com.rongxun.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextSwitcher;
import android.widget.TextView;

import com.rongxun.base.BaseObserver;
import com.rongxun.hbwallet.MyApp;
import com.rongxun.hbwallet.R;
import com.rongxun.hbwallet.model.bean.User;
import com.rongxun.hbwallet.mvp.model.ApiModel;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.disposables.CompositeDisposable;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/8/11 14:48
 * 描述
 */
public class MentionMoneyPasswordDialog extends Dialog {
    private static CompositeDisposable disposable;
    private static Dialog mLoadingDialog;

    public MentionMoneyPasswordDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        disposable = new CompositeDisposable();
        mLoadingDialog = LoadingDialog.createLoadingDialog(context, "加载中", false);
    }
    public static class Builder {
        private Context context;
        private MentionMoneyPasswordDialog dialog;
        protected Unbinder bind;
        @BindView(R.id.dialog_timeText)
        TimeTexView timeTexView;
        private ApiModel apiModel;
        public Builder(Context context) {
            this.context = context;
            apiModel = new ApiModel(context);
        }
        public MentionMoneyPasswordDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            dialog = new MentionMoneyPasswordDialog(context, R.style.Dialog);
            View layout = inflater.inflate(R.layout.dialog_mentionmoneypassword, null);
            bind = ButterKnife.bind(this, layout);
            dialog.getWindow().setWindowAnimations(R.style.anim_menu_bottombar);
            dialog.getWindow().setGravity(Gravity.BOTTOM);
            dialog.addContentView(layout, new LinearLayout.LayoutParams(
                    MyApp.SCREEN_WIDTH, LinearLayout.LayoutParams.WRAP_CONTENT));
            return dialog;
        }

        private void getMobileNumber() {
            disposable.add(apiModel
                    .getDealMobileCode()
                    .subscribeWith(new BaseObserver<User>() {
                                       @Override
                                       protected void onStart() {
                                           super.onStart();
                                           mLoadingDialog.show();
                                       }
                                       @Override
                                       public void onSuccess(User user, Context context) {
                                           mLoadingDialog.hide();
                                       }
                                       @Override
                                       public void onFailure(int code, String message) {
                                           super.onFailure(code, message);
                                           mLoadingDialog.hide();

                                       }
                                   }
                    ));
        }

        @OnClick({R.id.dialog_but_cancel, R.id.dialog_timeText})
        public void onViewClicked(View view) {
            if (view.getId() == R.id.dialog_but_cancel) {
                dialog.dismiss();
                bind.unbind();
            } else if (view.getId() == R.id.dialog_timeText) {
                getMobileNumber();
            }
        }
    }
}